<template>
  <div id="main">
    <h2>学员教学计划</h2>

    <div class="head">
      <el-button
        v-if="this.jurisdiction === '教务主任'"
        type="primary"
        style="margin:20px"
        @click="handleOpen('添加计划', 1)"
      >添加计划</el-button>
      <el-input
        v-model="searchTableInfo"
        placeholder="请输入搜索内容"
        style="width:240px;float: right;margin:20px;"
      />
    </div>
    <div id="table-area">
      <el-table
        v-loading="listLoading"
        :data="list.slice((currentPage - 1) * pagesize, currentPage * pagesize)"
        border
        fit
        highlight-current-row
      >
        <el-table-column
          label="序号"
          type="index"
          align="center"
        >
          <template scope="scope">
            <span>{{ (currentPage - 1) * pagesize + scope.$index + 1 }}</span>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          prop="plansStudentName"
          label="姓名"
        />

        <el-table-column
          align="center"
          prop="plansStudentAge"
          :formatter="formatAge"
          label="年龄"
        />

        <el-table-column
          align="center"
          prop="plansStudentSex"
          label="性别"
          :formatter="formatSex"
        />

        <el-table-column
          align="center"
          prop="plansSetStudentJoinTime"
          label="训练时长（天）"
        />

        <el-table-column
          align="center"
          prop="courseSummaryClazzTypeName"
          label="课程类型"
        />

        <el-table-column
          align="center"
          prop="courseSummaryTechnicalTypeName"
          label="技术类别"
        />
        <el-table-column
          align="center"
          prop="plansTeacherName"
          label="授课教师"
        />
        <el-table-column
          align="center"
          prop="plansPrincipalTeacherName"
          label="主责老师"
        />
        <el-table-column
          align="center"
          :formatter="dateFormat"
          prop="plansPostTime"
          label="录入时间"
        />
        <el-table-column
          align="center"
          label="操作"
        >
          <template slot-scope="Scope">
            <el-button
              v-if="jurisdiction=='教学主管'||jurisdiction=='教务主任'"
              type="primary"
              icon="el-icon-edit"
              @click="handleOpen('修改计划', 2, Scope.row.plansId)"
            >编辑</el-button>

            <el-button
              v-else
              type="primary"
              icon="el-icon-search"
              @click="handleOpen('修改计划', 2, Scope.row.plansId)"
            >查看</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div id="pages">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[5, 10]"
          :page-size="pagesize"
          layout="total, sizes,prev, pager, next"
          :total="list.length"
          prev-text="上一页"
          next-text="下一页"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>

    <el-dialog
      v-if="jurisdiction=='教学主管'||jurisdiction=='教务主任'"
      title=""
      :close-on-click-modal="false"
      :visible.sync="dialogFormVisible"
      :before-close="handleClose"
    >
      <el-form
        ref="plans"
        :model="plans"
        label-position="top"
        :rules="rules"
      >

        <el-form-item
          prop="plansStudentId"
          label="学生"
          :label-width="formLabelWidth"
        >
          <el-select
            v-model="plans.plansStudentId"
            placeholder="请选择"
            filterable
            style="width: 100%;"
          >
            <el-option
              v-for="j in child"
              :key="j.studentId"
              :value="j.studentId"
              :label="j.String"
            />
          </el-select>
        </el-form-item>

        <el-form-item
          prop="plansClazzId"
          label="班级"
          :label-width="formLabelWidth"
        >
          <el-select
            v-model="plans.plansClazzId"
            placeholder="请选择"
            filterable
            style="width: 100%;"
          >
            <el-option
              v-for="j in clazz"
              :key="j.classId"
              :value="j.classId"
              :label="j.className"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          prop="plansPeopleTeacherId"
          label="授课老师"
          :label-width="formLabelWidth"
        >
          <el-select
            v-model="plans.plansPeopleTeacherId"
            placeholder="请选择"
            filterable
            style="width: 100%;"
          >
            <el-option
              v-for="j in staffTeacher"
              :key="j.staffId"
              :value="j.staffId"
              :label="j.String"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          prop="plansPeopleResponsibleTeacherId"
          label="主责老师"
          :label-width="formLabelWidth"
        >
          <el-select
            v-model="plans.plansPeopleResponsibleTeacherId"
            placeholder="请选择"
            filterable
            style="width: 100%;"
          >
            <el-option
              v-for="j in staffResponsibleTeacher"
              :key="j.staffId"
              :value="j.staffId"
              :label="j.String"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          prop="plansTeachingSupervisorId"
          label="教学主管"
          :label-width="formLabelWidth"
        >
          <el-select
            v-model="plans.plansTeachingSupervisorId"
            placeholder="请选择"
            filterable
            style="width: 100%;"
          >
            <el-option
              v-for="j in staffTeachingSupervisor"
              :key="j.staffId"
              :value="j.staffId"
              :label="j.String"
            />
          </el-select>
        </el-form-item>

        <el-form-item
          v-if="jurisdiction === '教学主管'||jurisdiction === '责任教师'||jurisdiction === '授课老师'"
          prop="plansStageGoal"
          label="阶段目标"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="plans.plansStageGoal"
            autocomplete="off"
            maxlength="500"
            show-word-limit
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 20 }"
            placeholder="请输入内容"
            :readonly="readonly"
          />
        </el-form-item>
        <el-form-item
          v-if="jurisdiction === '教学主管'||jurisdiction === '责任教师'||jurisdiction === '授课老师'"
          prop="plansTrainingPrograms"
          label="训练项目"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="plans.plansTrainingPrograms"
            autocomplete="off"
            maxlength="500"
            show-word-limit
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 20 }"
            placeholder="请输入内容"
            :readonly="readonly"
          />
        </el-form-item>
        <el-form-item
          v-if="jurisdiction === '教学主管'||jurisdiction === '责任教师'||jurisdiction === '授课老师'"
          prop="plansTeachingPreparation"
          label="教学准备"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="plans.plansTeachingPreparation"
            autocomplete="off"
            maxlength="500"
            show-word-limit
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 20 }"
            placeholder="请输入内容"
            :readonly="readonly"
          />
        </el-form-item>
        <el-form-item
          v-if="jurisdiction === '教学主管'||jurisdiction === '责任教师'||jurisdiction === '授课老师'"
          prop="plansMattersNeedingAttention"
          label="注意事项"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="plans.plansMattersNeedingAttention"
            autocomplete="off"
            maxlength="500"
            show-word-limit
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 20 }"
            placeholder="请输入内容"
            :readonly="readonly"
          />
        </el-form-item>

      </el-form>
      <div
        slot="footer"
        class="dialog-footer"
      >
        <el-button
          v-if=" editType == 2 && (jurisdiction === '教学主管'||jurisdiction == '教务主任')"
          type="primary"
          @click="handleUpdate('plans')"
        >修 改</el-button>
        <el-button
          v-if="editType == 1 && jurisdiction == '教务主任'"
          type="primary"
          @click="handleAddUser('plans')"
        >添 加</el-button>
      </div>
    </el-dialog>
    <el-dialog
      v-else
      title=""
      :close-on-click-modal="false"
      :visible.sync="dialogFormVisible"
      :before-close="handleClose"
    >
      <el-form
        ref="plans"
        :model="plans"
        label-position="top"
        :rules="rules"
      >

        <el-form-item
          prop="plansStudentId"
          label="学生"
          :label-width="formLabelWidth"
        >
          <el-tag
            type="info"
            effect="plain"
          >
            {{ plans.plansStudentName }}
          </el-tag>
        </el-form-item>

        <el-form-item
          prop="plansClazzId"
          label="班级"
          :label-width="formLabelWidth"
        >
          <el-tag
            type="info"
            effect="plain"
          >
            {{ ClassName }}
          </el-tag>
        </el-form-item>
        <el-form-item
          prop="plansPeopleTeacherId"
          label="授课老师"
          :label-width="formLabelWidth"
        >
          <el-tag
            type="info"
            effect="plain"
          >
            {{ plans.plansTeacherName }}
          </el-tag>
        </el-form-item>
        <el-form-item
          prop="plansPeopleResponsibleTeacherId"
          label="主责老师"
          :label-width="formLabelWidth"
        >
          <el-tag
            type="info"
            effect="plain"
          >
            {{ plans.plansPrincipalTeacherName }}
          </el-tag>
        </el-form-item>
        <el-form-item
          prop="plansTeachingSupervisorId"
          label="教学主管"
          :label-width="formLabelWidth"
        >
          <el-tag
            type="info"
            effect="plain"
          >
            {{ plans.plansTeachingSupervisorName }}
          </el-tag>
        </el-form-item>

        <el-form-item
          v-if="jurisdiction === '教学主管'||jurisdiction === '责任教师'||jurisdiction === '授课老师'"
          prop="plansStageGoal"
          label="阶段目标"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="plans.plansStageGoal"
            autocomplete="off"
            maxlength="500"
            show-word-limit
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 20 }"
            placeholder="请输入内容"
            :readonly="readonly"
          />
        </el-form-item>
        <el-form-item
          v-if="jurisdiction === '教学主管'||jurisdiction === '责任教师'||jurisdiction === '授课老师'"
          prop="plansTrainingPrograms"
          label="训练项目"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="plans.plansTrainingPrograms"
            autocomplete="off"
            maxlength="500"
            show-word-limit
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 20 }"
            placeholder="请输入内容"
            :readonly="readonly"
          />
        </el-form-item>
        <el-form-item
          v-if="jurisdiction === '教学主管'||jurisdiction === '责任教师'||jurisdiction === '授课老师'"
          prop="plansTeachingPreparation"
          label="教学准备"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="plans.plansTeachingPreparation"
            autocomplete="off"
            maxlength="500"
            show-word-limit
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 20 }"
            placeholder="请输入内容"
            :readonly="readonly"
          />
        </el-form-item>
        <el-form-item
          v-if="jurisdiction === '教学主管'||jurisdiction === '责任教师'||jurisdiction === '授课老师'"
          prop="plansMattersNeedingAttention"
          label="注意事项"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="plans.plansMattersNeedingAttention"
            autocomplete="off"
            maxlength="500"
            show-word-limit
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 20 }"
            placeholder="请输入内容"
            :readonly="readonly"
          />
        </el-form-item>

      </el-form>
      <div
        slot="footer"
        class="dialog-footer"
      >
        <el-button
          v-if=" editType == 2 && (jurisdiction === '教学主管'||jurisdiction == '教务主任')"
          type="primary"
          @click="handleUpdate('plans')"
        >修 改</el-button>
        <el-button
          v-if="editType == 1 && jurisdiction == '教务主任'"
          type="primary"
          @click="handleAddUser('plans')"
        >添 加</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { getAllplans, getAllplansByTeacher, getAllplansA, addplans, deleteplans, updateplans, getplansById, getAllplansByMedicalID, getAllplansByDirector } from '@/api/plans'
import { selectclazz } from '@/api/teachsummary'
import store from '@/store/index'
import { selectstaff } from '@/api/staff'
import { selectStudent } from '@/api/child'
import { selectstaffTeacher, getStaffStringR, getStaffStringD } from '@/api/staff'

import moment from 'moment'
export default {
  data () {
    return {
      jurisdiction: '',
      BB: store.getters.userId,
      newplans: {
        plansAdmissionAssessment: '',
        plansId: ''
      },
      value: '',
      ClassName: '',
      currentPage: 1, // 默认显示页面为1
      pagesize: 5, //    每页的数据条数
      readonly: false,
      tableList: [],
      staffTeacher: {},
      staffResponsibleTeacher: {},
      staffTeachingSupervisor: {},
      searchTableInfo: '',
      plans: {},
      listLoading: false,
      dialogFormVisible: false,
      editType: 1, // 1 添加 2 修改
      child: {},
      clazz: {},
      staff: {},
      formLabelWidth: '200px',
      teacher: '',
      rules: {
        plansStudentId: [
          { required: true, message: '学生不能为空', trigger: ['blur', 'change'] }
        ],
        plansClazzId: [{
          required: true, message: '班级不能为空', trigger: ['blur', 'change']
        }],
        plansPeopleTeacherId: [{
          required: true, message: '授课老师不能为空', trigger: ['blur', 'change']
        }],
        plansPeopleResponsibleTeacherId: [{
          required: true, message: '主责老师不能为空', trigger: ['blur', 'change']
        }],
        plansTeachingSupervisorId: [{
          required: true, message: '教学主管不能为空', trigger: ['blur', 'change']
        }],
        plansStageGoal: [
          { required: true, message: '阶段目标不能为空', trigger: 'blur' }
        ],
        plansTrainingPrograms: [
          { required: true, message: '训练项目不能为空', trigger: 'blur' }
          //  {validator:validateChineseName, trigger: ['blur', 'change']},
        ],
        plansTeachingPreparation: [
          { required: true, message: '教学准备不能为空', trigger: 'blur' }

        ],
        plansMattersNeedingAttention: [
          { required: true, message: '注意事项不能为空', trigger: 'blur' }
          // {validator:validateChineseName, trigger: ['blur', 'change']},
        ]
      }
    }
  },
  computed: {
    // 根据计算属性模糊搜索
    list () {
      const searchTableInfo = this.searchTableInfo
      if (searchTableInfo) {
        // filter() 方法创建一个新的数组，新数组中的元素是通过检查指定数组中符合条件的所有元素。
        // 注意： filter() 不会对空数组进行检测。
        // 注意： filter() 不会改变原始数组。
        return this.tableList.filter(data => {
          // some() 方法用于检测数组中的元素是否满足指定条件;
          // some() 方法会依次执行数组的每个元素：
          // 如果有一个元素满足条件，则表达式返回true , 剩余的元素不会再执行检测;
          // 如果没有满足条件的元素，则返回false。
          // 注意： some() 不会对空数组进行检测。
          // 注意： some() 不会改变原始数组。
          return Object.keys(data).some(key => {
            // indexOf() 返回某个指定的字符在某个字符串中首次出现的位置，如果没有找到就返回-1；
            // 该方法对大小写敏感！所以之前需要toLowerCase()方法将所有查询到内容变为小写。
            return (
              String(data[key])
                .toLowerCase()
                .indexOf(searchTableInfo) > -1
            )
          })
        })
      }
      return this.tableList
    }
  },
  created () {
    this.jurisdiction = store.getters.roles[0]

    this.fetchData()
    this.getinfo()
  },
  methods: {
    // 时间格式化
    dateFormat (row, column) {
      var date = row[column.property]
      if (date === undefined) {
        return ''
      }
      return moment(date).format('YYYY-MM-DD')
    },
    // 时间格式化
    formatSex: function (row, column, cellValue) {
      if (cellValue === '1') {
        return '女'
      } else if (cellValue === '0') {
        return '男'
      }
    },

    formatAge: function (row, column, cellValue) {
      if (cellValue === -1) {
        return '未填写'
      } else {
        return cellValue
      }
    },
    // 每页下拉显示数据
    handleSizeChange: function (size) {
      this.pagesize = size
    },
    // 点击第几页
    handleCurrentChange: function (currentPage) {
      this.currentPage = currentPage
    },
    getinfo: function () {
      selectStudent().then((resp) => {
        this.child = resp.data.records
      })
      selectstaff().then((resp) => {
        this.staff = resp.data.records
      })

      selectstaffTeacher().then((resp) => {
        this.staffTeacher = resp.data.records
      })

      getStaffStringR().then((resp) => {
        this.staffResponsibleTeacher = resp.data.records
      })
      getStaffStringD().then((resp) => {
        this.staffTeachingSupervisor = resp.data.records
      })
      selectclazz().then((resp) => {
        this.clazz = resp.data.records
      })
    },
    handleClick (row) {

    },
    fetchData () {
      this.tableList = []
      this.listLoading = true
      if (this.jurisdiction === '教务主任') {
        getAllplans().then(data => {
          this.newplans

          for (var i = 0; i < data.data.records.length; i++) {
            this.newplans.plansId = data.data.records[i].plansId
            this.newplans.plansPeopleName = data.data.records[i].plansPeopleName
            this.newplans.plansStudentName = data.data.records[i].plansStudentName
            this.newplans.plansTeacherName = data.data.records[i].plansTeacherName
            this.newplans.plansPostTime = data.data.records[i].plansPostTime
            this.newplans.plansLessonPlan = data.data.records[i].plansLessonPlan
            this.newplans.studentName = data.data.records[i].studentName
            this.newplans.plansStudentAge = data.data.records[i].plansStudentAge
            this.newplans.plansStudentSex = data.data.records[i].plansStudentSex
            this.newplans.plansSetStudentJoinTime = data.data.records[i].plansSetStudentJoinTime
            this.newplans.studentTreatPrincipalTeacherName = data.data.records[i].studentTreatPrincipalTeacherName
            this.newplans.plansTeacherName = data.data.records[i].plansTeacherName
            this.newplans.courseSummaryClazzTypeName = data.data.records[i].courseSummaryClazzTypeName
            this.newplans.courseSummaryTechnicalTypeName = data.data.records[i].courseSummaryTechnicalTypeName
            this.newplans.plansPrincipalTeacherName = data.data.records[i].plansPrincipalTeacherName
            this.newplans.PlansPeopleTeacherId = data.data.records[i].PlansPeopleTeacherId
            this.tableList.push(this.newplans)
            this.newplans = {}
          }

          this.listLoading = false
        })
      } else if (this.jurisdiction === '医疗主管') {
        getAllplansByMedicalID(this.BB).then(data => {
          this.newplans
          for (var i = 0; i < data.data.length; i++) {
            this.newplans.plansId = data.data[i].plansId
            this.newplans.plansPeopleName = data.data[i].plansPeopleName
            this.newplans.plansStudentName = data.data[i].plansStudentName
            this.newplans.plansTeacherName = data.data[i].plansTeacherName
            this.newplans.plansPostTime = data.data[i].plansPostTime
            this.newplans.plansLessonPlan = data.data[i].plansLessonPlan
            this.newplans.studentName = data.data[i].studentName
            this.newplans.plansStudentAge = data.data[i].plansStudentAge
            this.newplans.plansStudentSex = data.data[i].plansStudentSex
            this.newplans.plansSetStudentJoinTime = data.data[i].plansSetStudentJoinTime
            this.newplans.studentTreatPrincipalTeacherName = data.data[i].studentTreatPrincipalTeacherName
            this.newplans.plansTeacherName = data.data[i].plansTeacherName
            this.newplans.courseSummaryClazzTypeName = data.data[i].courseSummaryClazzTypeName
            this.newplans.courseSummaryTechnicalTypeName = data.data[i].courseSummaryTechnicalTypeName
            this.newplans.plansPrincipalTeacherName = data.data[i].plansPrincipalTeacherName
            this.newplans.PlansPeopleTeacherId = data.data[i].PlansPeopleTeacherId
            this.tableList.push(this.newplans)
            this.newplans = {}
          }
          this.listLoading = false
        })
      } else if (this.jurisdiction === '教学主任') {
        getAllplansA(this.BB).then(data => {
          this.newplans
          for (var i = 0; i < data.data.length; i++) {
            this.newplans.plansId = data.data[i].plansId
            this.newplans.plansPeopleName = data.data[i].plansPeopleName
            this.newplans.plansStudentName = data.data[i].plansStudentName
            this.newplans.plansTeacherName = data.data[i].plansTeacherName
            this.newplans.plansPostTime = data.data[i].plansPostTime
            this.newplans.plansLessonPlan = data.data[i].plansLessonPlan
            this.newplans.studentName = data.data[i].studentName
            this.newplans.plansStudentAge = data.data[i].plansStudentAge
            this.newplans.plansStudentSex = data.data[i].plansStudentSex
            this.newplans.plansSetStudentJoinTime = data.data[i].plansSetStudentJoinTime
            this.newplans.studentTreatPrincipalTeacherName = data.data[i].studentTreatPrincipalTeacherName
            this.newplans.plansTeacherName = data.data[i].plansTeacherName
            this.newplans.courseSummaryClazzTypeName = data.data[i].courseSummaryClazzTypeName
            this.newplans.courseSummaryTechnicalTypeName = data.data[i].courseSummaryTechnicalTypeName
            this.newplans.plansPrincipalTeacherName = data.data[i].plansPrincipalTeacherName
            this.newplans.PlansPeopleTeacherId = data.data[i].PlansPeopleTeacherId
            this.tableList.push(this.newplans)
            this.newplans = {}
          }
          this.listLoading = false
        })
      } else if (this.jurisdiction === '教学主管') {
        getAllplansByDirector(this.BB).then(data => {
          this.newplans
          for (var i = 0; i < data.data.length; i++) {
            this.newplans.plansId = data.data[i].plansId
            this.newplans.plansPeopleName = data.data[i].plansPeopleName
            this.newplans.plansStudentName = data.data[i].plansStudentName
            this.newplans.plansTeacherName = data.data[i].plansTeacherName
            this.newplans.plansPostTime = data.data[i].plansPostTime
            this.newplans.plansLessonPlan = data.data[i].plansLessonPlan
            this.newplans.studentName = data.data[i].studentName
            this.newplans.plansStudentAge = data.data[i].plansStudentAge
            this.newplans.plansStudentSex = data.data[i].plansStudentSex
            this.newplans.plansSetStudentJoinTime = data.data[i].plansSetStudentJoinTime
            this.newplans.studentTreatPrincipalTeacherName = data.data[i].studentTreatPrincipalTeacherName
            this.newplans.plansTeacherName = data.data[i].plansTeacherName
            this.newplans.courseSummaryClazzTypeName = data.data[i].courseSummaryClazzTypeName
            this.newplans.courseSummaryTechnicalTypeName = data.data[i].courseSummaryTechnicalTypeName
            this.newplans.plansPrincipalTeacherName = data.data[i].plansPrincipalTeacherName
            this.newplans.PlansPeopleTeacherId = data.data[i].PlansPeopleTeacherId
            this.tableList.push(this.newplans)
            this.newplans = {}
          }
          this.listLoading = false
        })
      } else if (this.jurisdiction === '责任教师') {
        getAllplansByDirector(this.BB).then(data => {
          this.newplans

          for (var i = 0; i < data.data.length; i++) {
            this.newplans.plansId = data.data[i].plansId
            this.newplans.plansPeopleName = data.data[i].plansPeopleName
            this.newplans.plansStudentName = data.data[i].plansStudentName
            this.newplans.plansTeacherName = data.data[i].plansTeacherName
            this.newplans.plansPostTime = data.data[i].plansPostTime
            this.newplans.plansLessonPlan = data.data[i].plansLessonPlan
            this.newplans.studentName = data.data[i].studentName
            this.newplans.plansStudentAge = data.data[i].plansStudentAge
            this.newplans.plansStudentSex = data.data[i].plansStudentSex
            this.newplans.plansSetStudentJoinTime = data.data[i].plansSetStudentJoinTime
            this.newplans.studentTreatPrincipalTeacherName = data.data[i].studentTreatPrincipalTeacherName
            this.newplans.plansTeacherName = data.data[i].plansTeacherName
            this.newplans.courseSummaryClazzTypeName = data.data[i].courseSummaryClazzTypeName
            this.newplans.courseSummaryTechnicalTypeName = data.data[i].courseSummaryTechnicalTypeName
            this.newplans.plansPrincipalTeacherName = data.data[i].plansPrincipalTeacherName
            this.newplans.PlansPeopleTeacherId = data.data[i].PlansPeopleTeacherId
            this.tableList.push(this.newplans)
            this.newplans = {}
          }
          this.listLoading = false
        })
      } else {
        getAllplansByTeacher(this.BB).then(data => {
          this.newplans

          for (var i = 0; i < data.data.length; i++) {
            this.newplans.plansId = data.data[i].plansId
            this.newplans.plansPeopleName = data.data[i].plansPeopleName
            this.newplans.plansStudentName = data.data[i].plansStudentName
            this.newplans.plansTeacherName = data.data[i].plansTeacherName
            this.newplans.plansPostTime = data.data[i].plansPostTime
            this.newplans.plansLessonPlan = data.data[i].plansLessonPlan
            this.newplans.studentName = data.data[i].studentName
            this.newplans.plansStudentAge = data.data[i].plansStudentAge
            this.newplans.plansStudentSex = data.data[i].plansStudentSex
            this.newplans.plansSetStudentJoinTime = data.data[i].plansSetStudentJoinTime
            this.newplans.studentTreatPrincipalTeacherName = data.data[i].studentTreatPrincipalTeacherName
            this.newplans.plansTeacherName = data.data[i].plansTeacherName
            this.newplans.courseSummaryClazzTypeName = data.data[i].courseSummaryClazzTypeName
            this.newplans.courseSummaryTechnicalTypeName = data.data[i].courseSummaryTechnicalTypeName
            this.newplans.plansPrincipalTeacherName = data.data[i].plansPrincipalTeacherName
            this.newplans.PlansPeopleTeacherId = data.data[i].PlansPeopleTeacherId
            this.tableList.push(this.newplans)
            this.newplans = {}
          }
          this.listLoading = false
        })
      }
    },
    handleDelete (id) {
      this.$confirm('确认删除该记录？').then(() =>
        deleteplans(id).then(data => {
          this.$notify({
            title: '操作成功',
            type: 'success'
          })
          const totalPage = Math.ceil(
            (this.tableList.length - 1) / this.pagesize
          )
          const page =
            this.currentPage > totalPage ? totalPage : this.currentPage
          this.currentPage = this.currentPage < 1 ? 1 : page
          this.fetchData()
        })
      )
    },
    handleAddUser (formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          addplans(this.plans).then(resp => {
            this.$notify({
              title: '操作成功',
              type: 'success'
            })
            this.fetchData()
          })
            .catch(err => {
              console.log(err)
            })
          this.handleClose()
          return true
        } else {
          this.$notify({
            title: '请正确填写',
            type: 'error'
          })
          return false
        }
      })
    },

    handleOpen (title, type, id) {
      this.plans = {}
      this.title = title
      this.editType = type
      if (type === 2) {
        getplansById(id).then((resp) => {
          resp.data.records.plansPeopleTeacherId = resp.data.records.plansTeacherId
          resp.data.records.plansPeopleResponsibleTeacherId = resp.data.records.plansPrincipalTeacherId
          this.plans = resp.data.records
          if (this.jurisdiction === '教学主管' || this.jurisdiction === '教务主任') {
            this.readonly = false
          } else {
            for (let i = 0; i < this.clazz.length; i++) {
              if (this.plans.plansClazzId == this.clazz[i].classId) {
                this.ClassName = this.clazz[i].className
              }
            }
            this.readonly = true
          }
        })
        this.dialogFormVisible = true
      } else {
        this.dialogFormVisible = true
      }
    },
    handleClose () {
      this.dialogFormVisible = false
      this.$refs.plans.resetFields()
      this.plans = {}
    },
    handleUpdate (formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          if (this.jurisdiction === '教学主管') {
            this.plans.plansTeachingSupervisor = store.getters.userId
          }
          updateplans(this.plans).then(resp => {
            this.$notify({
              title: '修改成功',
              type: 'success'
            })
            this.fetchData()
          }).catch(resp => {
            this.fetchData()
          })
          this.handleClose()
          return true
        } else {
          this.$notify({
            title: '请正确填写',
            type: 'error'
          })
          return false
        }
      })
    }

  }
}
</script>

<style scoped>
#main {
  margin-left: 5px;
  margin-right: 5px;
}
#table-area {
  margin-left: 10px;
  margin-right: 10px;
}
</style>
